package com.asion.qkan.ui.view;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.asion.qkan.R;
import com.asion.qkan.adapters.HomeVPAdapter;
import com.asion.qkan.ui.fragment.MaterialFragment;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AuthorActivity extends AppCompatActivity {

    @BindView(R.id.author_tab)
    TabLayout authorTab;
    @BindView(R.id.author_viewpager)
    ViewPager authorViewpager;
    @BindView(R.id.author_img)
    SimpleDraweeView authorImg;
    @BindView(R.id.author_toolbar)
    Toolbar authorToolbar;
    @BindView(R.id.activity_user)
    CoordinatorLayout activityUser;
    @BindView(R.id.author_name)
    TextView authorName;


    private String[] titles = {"资料", "动态"};
    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_author);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        Bundle bundle = intent.getBundleExtra("bundle");

        String url = bundle.getString("url");
        authorImg.setImageURI(Uri.parse(url));

        setSupportActionBar(authorToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        String nickname = bundle.getString("name");
        authorName.setText(nickname);
        setTitle(null);


        //添加fragment
        MaterialFragment materialFragment = new MaterialFragment();
        materialFragment.setArguments(bundle);
        fragmentList.add(materialFragment);
        HomeVPAdapter homeVPAdapter = new HomeVPAdapter(getSupportFragmentManager(), fragmentList, titles);
        authorViewpager.setAdapter(homeVPAdapter);
        authorTab.setupWithViewPager(authorViewpager);

    }

    public static void startAction(Activity activity, Bundle bundle) {
        Intent intent = new Intent(activity, AuthorActivity.class);
        intent.putExtra("bundle", bundle);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.all_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
            case R.id.menu_focus:
                break;
        }
        return true;
    }
}
